<?php
require './include/common.inc.php';
if(isset($_POST['k']))
{
    $url = '/search.php?k='.urlencode($_POST['k']).'&t='.$_POST['t'];
    $response->redirect($url);
    $response->execute();
}
$flag = true;
if(!isset ($_GET['k']) || empty ($_GET['k']))
{
    $flag = false;
}
if($flag == true)
{
    if($_GET['t'] ==1)
    {
        $condition = " where modelid != '80759097-a856-102f-80c7-7e4d0a484dab' and modelid !='d2b56cbb-a858-102f-80c7-7e4d0a484dab' and status=3";
    }
    elseif($_GET['t']==2)
    {
        $condition = " where modelid ='d2b56cbb-a858-102f-80c7-7e4d0a484dab' and status=3";
    }
    else
    {
        $condition = " where modelid = '80759097-a856-102f-80c7-7e4d0a484dab' and status=3";
    }
    
    $db->prepare('select count(*) as nums from edufe_content ' . $condition . ' and title like ?');
    $db->set_string("%".urldecode($_GET['k']) . "%");
    $res_count = $db->execute(true);
    $count = $res_count['nums'];
    $page = isset ($_GET['page']) ? intval($_GET['page']) : 1;
    $page = max(1, $page);
    if($page == 1 && $count==0)
    {
        $flag = false;
    }
    else
    {
        
        $pagesize = 30;
        $total = ceil($count / $pagesize);
        $start = ($page - 1) * $pagesize;
        $db->prepare('select * from edufe_content ' . $condition .' and title like ? order by addtime desc limit ?,?');
        $db->set_string("%".urldecode($_GET['k']) . "%");
        $db->set_int($start);
        $db->set_int($pagesize);
        $list = $db->execute();
    }
    
    $page_title = '搜索  --  '.$site_conf->get('SITE_NAME');
    $css_file = 'complicate.css';
    include template('default', 'search');
}
?>
